package cn.jesin.ssmss01.controller;

import cn.jesin.ssmss01.common.Flag;
import cn.jesin.ssmss01.service.AdminService;
import cn.jesin.ssmss01.vo.Page;
import cn.jesin.ssmss01.vo.UserInfo;
import cn.jesin.ssmss01.vo.responseformat.Code;
import cn.jesin.ssmss01.vo.responseformat.Result;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.enums.ParameterIn;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author 谷汉斌
 * @description
 * @createTime 2024/8/13 上午10:41
 */
@Tag(name = "管理员控制器", description = "处理管理员请求")
@RestController
@RequestMapping("/admins")
public class AdminController {

    @Resource
    private AdminService adminService;

    /**
     * 管理员查询用户信息列表
     */
    @Operation(summary = "管理员分页查询用户信息列表", parameters = {
            @Parameter(name = "pageNum", description = "页码", in = ParameterIn.QUERY),
            @Parameter(name = "pageSize", description = "每页数量", in = ParameterIn.QUERY),
            @Parameter(name = "keys", description = "查询关键字", in = ParameterIn.QUERY),
    })
    @GetMapping("/userInfo_list")
    public Result<Page<UserInfo>> queryUserInfoList(
            @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
            @RequestParam(value = "pageSize", defaultValue = "6") Integer pageSize,
            @RequestParam(value = "keys", defaultValue = "") String keys) {
        Page<UserInfo> userInfoPage = adminService.queryUserInfoList(pageNum, pageSize, keys);
        return Result.<Page<UserInfo>>builder()
                .code(Code.QUERY_SUCCESS.getCode())
                .data(userInfoPage)
                .flag(Flag.SUCCESS.isCode())
                .message(Code.QUERY_SUCCESS.getInfo())
                .build();
    }
}
